home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-08-07 | 5.6 KB | 220 lines | [TEXT/MPS ] |
- UNIT cdev;
-
- INTERFACE
-
- USES MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf;
-
- FUNCTION Sample(message, Item, numItems, CPanelID: INTEGER;
- VAR evt: EventRecord; cdevValue: LONGINT;
- CPDialog: DialogPtr): LONGINT; FORWARD;
-
- IMPLEMENTATION
-
- CONST
- iVersion = 1;
- iTitle = 2;
- iShowCounts = 3;
- iHideCounts = 4;
- iTitleHandled = 5;
- iTitleIgnored = 6;
- iHandled = 7;
- iIgnored = 8;
-
- TYPE
- SampleStorage = RECORD
- dlgPtr: DialogPtr;
- dlgItems: integer;
- countShown: Boolean;
- msgHandled: integer;
- msgIgnored: integer;
- END;
- SamplePtr = ^SampleStorage;
- SampleHdl = ^SamplePtr;
-
- FUNCTION InitSample(CPDialog : DialogPtr; numItems: integer): longInt; FORWARD;
- FUNCTION EnoughRoomToRun(var cdevValue : longInt): Boolean; FORWARD;
- PROCEDURE CountMessage(ourHandle: SampleHdl; handledIt: Boolean); FORWARD;
- PROCEDURE HitSample(ourHandle: SampleHdl; item: integer); FORWARD;
- PROCEDURE DrawSampleItem(ourHandle: SampleHdl; item: integer); FORWARD;
- FUNCTION IGetCtlHand(ourHandle: SampleHdl; item: integer): ControlHandle; FORWARD;
- PROCEDURE IGetRect(ourHandle: SampleHdl; item: integer; var itemRect: Rect); FORWARD;
- PROCEDURE IHide(ourHandle: SampleHdl; item: integer); FORWARD;
- PROCEDURE IShow(ourHandle: SampleHdl; item: integer); FORWARD;
- PROCEDURE IInvalidate(ourHandle: SampleHdl; item: integer); FORWARD;
-
- FUNCTION Sample(message, Item, numItems, CPanelID: INTEGER;
- VAR evt: EventRecord; cdevValue: LONGINT;
- CPDialog: DialogPtr): LONGINT;
- VAR i: integer;
- handledIt: Boolean;
- ourHandle: SampleHdl;
- storageExpected: Boolean;
- BEGIN
- storageExpected := not ((message = initDev) or (message = macDev));
- if storageExpected and ((cdevValue = 0) or (cdevValue = cdevUnset)) then
- BEGIN
- cdevValue := 0;
- END
- else if storageExpected and not EnoughRoomToRun(cdevValue) then
- BEGIN
- END
- else
- BEGIN
- HandledIt := true;
- ourHandle := SampleHdl(cdevValue);
- case message of
- initDev: if EnoughRoomToRun(cdevValue) then BEGIN
- cdevValue := InitSample(CPDialog, numItems);
- ourHandle := SampleHdl(cdevValue);
- END;
- closeDev: if ourHandle <> nil then BEGIN
- DisposHandle(Handle(ourHandle));
- cdevValue := 0;
- ourHandle := nil;
- END;
- hitDev: HitSample(ourHandle, item - numItems);
- updateDev: for i := iHandled to iIgnored do
- DrawSampleItem(ourHandle,i);
- otherwise handledIt := false;
- END; {of case}
- if ourHandle <> nil then
- CountMessage(ourHandle, handledIt);
- END;
- Sample := cdevValue;
- END;
-
- FUNCTION InitSample(CPDialog : DialogPtr; numItems: integer): longInt;
- VAR i: integer;
- ourHandle: SampleHdl;
- BEGIN
- ourHandle := SampleHdl( NewHandle(sizeof(SampleStorage)));
- if ourHandle <> nil then BEGIN
- with ourHandle^^ do BEGIN
- dlgPtr := CPDialog;
- dlgItems := numItems;
- msgHandled := 0;
- msgIgnored := 0;
- countShown := true;
- END; {with}
- for i := iShowCounts to iHideCounts do
- SetCtlValue(IGetCtlHand(ourHandle, i), ORD(i=iShowCounts));
- END; {if}
- InitSample := ORD4(ourHandle);
- END;
-
- FUNCTION EnoughRoomToRun(var cdevValue : longInt): Boolean;
- VAR error: integer;
- packHand: Handle;
- BEGIN
- EnoughRoomToRun := true;
- Exit(EnoughRoomToRun);
- packHand := RGetResource('PACK',7);
- if packHand <> nil then BEGIN
- EnoughRoomToRun := true;
- Exit(EnoughRoomToRun)
- END;
-
- if ResError = resNotFound then
- error := cdevResErr
- else
- error := cdevMemErr;
-
- if (cdevValue <> cdevUnset) and (Handle(cdevValue) <> nil) then
- DisposHandle(Handle(cdevValue));
- cdevValue := error;
- EnoughRoomToRun := false;
- END;
-
-
- PROCEDURE CountMessage(ourHandle: SampleHdl; handledIt: Boolean);
- BEGIN
- if ourHandle <> nil then
- with ourHandle^^ do
- if handledIt then BEGIN
- msgHandled := msgHandled + 1;
- DrawSampleItem(ourHandle, iHandled);
- END
- else BEGIN
- msgIgnored := msgIgnored + 1;
- DrawSampleItem(ourHandle, iIgnored);
- END
- END;
-
- PROCEDURE HitSample(ourHandle: SampleHdl; item: integer);
- var i: integer;
- BEGIN
- with ourHandle^^ do
- if countShown <> (item = iShowCounts) then
- countShown := (item = iShowCounts)
- else
- Exit(HitSample);
- for i := iShowCounts to iHideCounts do
- SetCtlValue(IGetCtlHand(ourHandle,i), ORD(i=item));
- for i:= iTitleHandled to iIgnored do BEGIN
- if item = iShowCounts then
- IShow(ourHandle,i)
- else
- IHide(ourHandle,i);
- IInvalidate(ourHandle, i);
- END;
- END;
-
- PROCEDURE DrawSampleItem(ourHandle: SampleHdl; item: integer);
- VAR itemRect: Rect;
- s: Str255;
- BEGIN
- IGetRect(ourHandle, item, itemRect);
- with ourHandle^^ do BEGIN
- SetPort(dlgPtr);
- if item = iHandled then
- NumToString(msgHandled, s)
- else
- NumToString(msgIgnored, s);
- END;
- with itemRect do
- MoveTo(left, bottom);
- TextMode(srcCopy);
- DrawString(s);
- TextMode(srcOr);
- END;
-
- FUNCTION IGetCtlHand(ourHandle: SampleHdl; item: integer): ControlHandle;
- VAR itemHand: Handle;
- itemRect: Rect;
- itemType: integer;
- BEGIN
- with ourHandle^^ do
- GetDItem(dlgPtr, item + dlgItems, itemType, itemHand, itemRect);
- IGetCtlHand := ControlHandle(itemHand);
- END;
-
- PROCEDURE IGetRect(ourHandle: SampleHdl; item: integer; var itemRect: Rect);
- VAR itemType: integer;
- itemHand: Handle;
- BEGIN
- with ourHandle^^ do
- GetDItem(dlgPtr, item + dlgItems, itemType, itemHand, itemRect);
- END;
-
- PROCEDURE IHide(ourHandle: SampleHdl; item: integer);
- BEGIN
- with ourHandle^^ do
- HideDItem(dlgPtr, item+dlgItems);
- END;
-
- PROCEDURE IShow(ourHandle: SampleHdl; item: integer);
- BEGIN
- with ourHandle^^ do
- ShowDItem(dlgPtr, item+dlgItems);
- END;
-
- PROCEDURE IInvalidate(ourHandle: SampleHdl; item: integer);
- VAR itemRect: Rect;
- BEGIN
- IGetRect(ourHandle, item, itemRect);
- EraseRect(itemRect);
- InvalRect(itemRect);
- END;
-
- END. { of implementation }
-